# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgbase=ibus
pkgname=(ibus libibus)
pkgver=1.5.28
pkgrel=4
pkgdesc="Next Generation Input Bus for Linux"
arch=('loong64' 'x86_64')
url="https://github.com/ibus/ibus/wiki"
license=('LGPL')
depends=('dconf' 'gtk3' 'hicolor-icon-theme' 'libnotify' 'python-dbus' 'python-gobject'
         'iso-codes' 'librsvg')
makedepends=('gobject-introspection' 'vala' 'intltool' 'gnome-common' 'gtk-doc' 'gtk4' 'gtk2'
             'qt5-base' 'unicode-cldr' 'unicode-character-database' 'unicode-emoji')
options=('!emptydirs')
source=("https://github.com/ibus/ibus/releases/download/$pkgver/ibus-$pkgver.tar.gz"
         https://github.com/ibus/ibus/commit/497f0c74.patch
         https://github.com/ibus/ibus/commit/7c8abbe8.patch)
sha512sums=('5bfb9158a5810d38af900775ed30406823872c431ef4772b476afa7b58c120ef508a51b961620ea6003549f1f49cf05484992beee8677b138f1162afc73ab247'
            '1f3122187b5aead076f1fae81898a5dc2c36b96226d28683cdb313fe15c01858831726dca248f9e6b3664a4345f45eab479e5ea9e5c9eb9aa5f9ac7fd57a8073'
            '9c22745c49952944e47b5663357662a9f7538f2dba9252403669a1355b466e524e24d0636f1f49e597fe12f3c47e16bfc4359ec028678e2871e1b645241b3ebb')

prepare() {
  patch -d $pkgbase-$pkgver -p1 < 7c8abbe8.patch
  patch -d $pkgbase-$pkgver -p1 < 497f0c74.patch # Fix sticky keys
}

build() {
  cd ibus-$pkgver
  ./configure \
    --prefix=/usr \
    --libexecdir=/usr/lib/ibus \
    --sysconfdir=/etc \
    --enable-dconf \
    --enable-wayland \
    --enable-gtk-doc \
    --enable-gtk4 \
    --disable-memconf \
    --enable-ui \
    --disable-python2 \
    --with-python=python3 \
    --with-ucd-dir=/usr/share/unicode/
  sed -i 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package_ibus() {
  depends+=("libibus=$pkgver")

  cd ibus-$pkgver
  make DESTDIR="$pkgdir" install
  make -C src DESTDIR="$pkgdir" uninstall
  make -C bindings DESTDIR="$pkgdir" uninstall
  make DESTDIR="$pkgdir" uninstall-pkgconfigDATA
}

package_libibus() {
  pkgdesc="IBus support library"
  depends=(libg{lib,object,io}-2.0.so)
  provides=('libibus-1.0.so')

  cd ibus-$pkgver
  make -C src DESTDIR="$pkgdir" install
  make -C bindings DESTDIR="$pkgdir" install
  make DESTDIR="$pkgdir" install-pkgconfigDATA
}
